<?php

namespace App\Exports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithColumnWidths;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Events\AfterSheet;

class BigBagManifestExport implements FromCollection, WithHeadings, WithColumnWidths, WithEvents
{
    protected $data;

    public function __construct(Collection $data)
    {
        $this->data = $data;
    }

    public function collection()
    {
        return $this->data;
    }

    public function headings(): array
    {
        return [
            'orderCode',
            'trackingNumber',
            'bigBagID',
            'transportNo',
            'mawbNumber',
            'fromLocation',
            'toLocation',
            'receiver_name',
            'receiver_phone',
            'receiver_mobile',
            'receiver_email',
            'receiver_zipCode',
            'receiver_address',
            'receiver_detailAddress',
            'sender_name',
            'sender_phone',
            'sender_mobile',
            'sender_email',
            'sender_zipCode',
            'sender_address',
            'sender_detailAddress',
            'weight',
            'weightUnit',
            'name',
            'localName',
            'categoryName',
            'price',
            'itemPrice',
            'priceUnit',
            'priceCurrency',
            'quantity',
            'hsCode',
            'declaredValue',
            'lvgPaid',
            'taxId'
        ];

    }

    public function columnWidths(): array
    {
        // 设置每列的宽度
        return [
            'A' => 20,
            'B' => 25,
            'C' => 20,
            'D' => 20,
            'E' => 20,
            'F' => 20,
            'J' => 20,
            'K' => 20,
            'L' => 20,
            'M' => 20,
            'N' => 20
            // 根据你的需求设置其他列的宽度
        ];
    }

    public function registerEvents(): array
    {
        return [
            AfterSheet::class => function(AfterSheet $event) {
                $event->sheet->getDelegate()->freezePane('A2');
            },
        ];
    }

}